package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.Message;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class MessageDao {

	private DBHelp<Message> db = new DBHelp<Message>();
	
	public void Save (String id,String content,String createtime,String t_employee_id,String t_project_id) {
		String sql = "insert into t_message(id,content,createtime,t_employee_id,t_project_id) values(?,?,?,?,?)";
		db.executeSQL(sql, id,content,createtime,t_employee_id,t_project_id);
	}
	
	public List<Message> FindAll () {
		String sql = "select id,content,createtime,t_employee_id,t_project_id from t_message";
		return db.executeQueryForList(sql, new MessageRowMapper());
	}
	
	private class MessageRowMapper implements RowMapper<Message> {
		
		public Message mapperRow (ResultSet rs) throws SQLException {
			
			Message message = new Message();
			message.setId(rs.getString("id"));
			message.setContent(rs.getString("content"));
			message.setCreatetime(rs.getString("createtime"));
			message.setT_employee_id(rs.getString("t_employee_id"));
			message.setT_project_id(rs.getString("t_project_id"));
			return message;
		}
	}
}
